<template>
  <div id="carcontent">
    <div class="sote" v-if="list.goo">
      <div v-if="title"   class="parentTitle" @click="goto" >{{ title }}</div>
      <ul>
        <li v-for="(item, i) in list.data" :key="i">
          <div @click="gotoDetails(item, 1)" class="center">
            <div class="thumb">
              <img :src="item.thumb?item.thumb:'../assets/images/img_default.png'" />
            </div>
            <span>{{ item.name }}</span>
          </div>
        </li>
      </ul>
    </div>
    <template v-if="list.data&&list.data.length!==0&&list.set.cat_level == 3">
      <div v-for="item in list.data" class="box" :key="item.id" >
        <a :href="item.adv_url" v-if="!fun.isTextEmpty(item.adv_img)" class="branch">
          <img style="width: 100%; max-height: 40vh;" :src="item.adv_img" />
        </a>
        <div class="sote">
          <h3 class="" v-if="item.name">
            <router-link :to="fun.getUrl('catelist', { id: item.id, fromHome: 1 })">{{ item.name }}</router-link>
          </h3>
          <ul v-if="item.has_many_children && item.has_many_children.length > 0">
            <li v-for="catshop in item.has_many_children" :key="catshop.id">
              <div  @click="gotoDetails(catshop,1)" class="center">
                <div class="thumb" >
                  <img :src="catshop.thumb?catshop.thumb:'../assets/images/img_default.png'" />
                </div>
                <span>{{ catshop.name }}</span>
              </div>
            </li>
          </ul>
        </div>
    </div>
  </template>
    <template v-if="!list.goo && list.set">
      <div class="sote" v-if="list.set.cat_level == 2">
      <div v-if="title" class="parentTitle">{{ title }}</div>
        <ul>
          <li v-for="(item, i) in list.data" :key="i">
            <div  @click="gotoDetails(item,1)"  class="center">
              <div class="thumb">
                <img :src="item.thumb?item.thumb:'../assets/images/img_default.png'" />
              </div>
              <span>{{ item.name }}</span>
            </div>
          </li>
        </ul>
      </div>
    </template>
    <div v-if="this.fun.isTextEmpty(list.data)">
      <img src="../assets/images/no-more-product.png" alt="" style="width: 5rem; margin-top: 6rem;" />
    </div>
    <!-- <div style="height:5rem"></div> -->
  </div>
</template>
<script>
export default {
  props: ['list','title','parentId'],
  data() {
    return {
      allLoaded: false,
      topStatus: '',
      advimg: window.localStorage.adv_img
      // ...
    };
  },
  activated() {},
  created() {
    window.list = this.list;
  },
  methods: {
    goto(){
      if(this.parentId){
        this.$router.push(this.fun.getUrl('catelist',{id: parentId, fromHome: 1 }))
      }
    },
    gotoDetails(item) {
      this.$emit("bindOneCategory", item);
    }
  }
};
</script>
<style lang="scss" rel="stylesheet/scss" scoped>
  .parentTitle {
      text-align: left;
      font-weight: bold;
      display: flex;
      align-items: center;
      line-height: 0.9rem;
      padding-top: 0.625rem;
      padding-left: 0.75rem;
      font-size: 0.9375rem;
      color: #00001C;
    }
#carcontent {
  color: #686868;
  .box{
    margin-top:1rem;
  }
  .box:first-child{
    margin-top: 0;
  }

  word-wrap: break-word;
  .branch {
    img{
      width: 100%;
      display: block;
      border-radius: 0.9375rem;
      max-height: 40vh;
      margin-bottom: 0.625rem;
    }
  }
  .center{
    display: flex;
    flex-direction: column;
    align-items: center;
  }
  .sote {
    clear: both;
    overflow: hidden;
    margin-bottom: 0.625rem;
    height: 100%;
    background: #fff;
    border-radius: 0.9375rem;
    span{
      font-weight: 500;
      margin-top: 0.6563rem;
      height: 0.8125rem;
      line-height: 0.8125rem;
    }
  }

  h3 {
    text-align: left;
    font-size: 0.9375rem;
    padding-left: 0.75rem;
    padding-top: 0.7813rem;
    margin-bottom: 0.9375rem;
    font-weight: bold;
    display: block;
    clear: both;
    color: #999;

    a {
      color: #333;
    }
  }

  .fa-bookmark::before {
    margin-right: 0.375rem;
  }

  a span {
    height: 1.875rem;
    line-height: 1.875rem;
    overflow: hidden;
    color: #686868;
    text-overflow: ellipsis;
    width: 100%;
    display: block;
    // display: -webkit-box;
    white-space: nowrap;
    text-align: -webkit-center;
  }

  .branch img {
    width: 100%;
  }

  .thumb {
    // line-height: 22.5vw;
    // overflow: hidden;
    // box-sizing: border-box;
    // width: 100%;
    // height: 0;
    // padding-bottom: 100%;
    // position: relative;
    width: 3.75rem;
    height: 3.75rem;
    border-radius: 0.9375rem;
  }

  ul {
    // clear: both;
    width: 100%;
    overflow: hidden;
    margin-top: 0.9375rem;
    background: #fff;
    box-sizing: border-box;
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
  }

  li {
    // width: 29%;
    text-align: center;
    // float: left;
    margin-bottom: 0.9375rem;
    // margin-right: 4%;
    font-size: 12px;
    background: #fff;

    img {
      // width: 98%;
      // right: 0;
      // height: 98%;
      // position: absolute;
      width: 3.75rem;
      height: 3.75rem;
      border-radius: 0.9375rem;
    }
  }

  li:nth-child(3n) {
    margin-right: 0;
  }
}
</style>
